import jieba
import jieba.posseg as pseg
from docx import Document

# 读取年报文本
def load_text(file_path):
    with open(file_path, "r", encoding="utf-8") as file:
        return file.read()

# 创建 Word 文档
def create_docx(filename):
    doc = Document()
    doc.add_heading('年报解读框架', 0)
    return doc

# 添加解读维度到文档
def add_dimension(doc, dimension, content):
    doc.add_heading(dimension, level=1)
    doc.add_paragraph(content)

# 保存文档
def save_docx(doc, filename):
    doc.save(filename)

# 提取关键信息
def extract_key_info(text):
    # 分词和词性标注
    words = pseg.cut(text)
    for word, flag in words:
        print(f'{word}/{flag}')  # 这行可以帮助你调试

# 主函数
def main():
    file_path = "D:\\vsc.py\\quanqiurenkou\\key_info.txt"
    context = load_text(file_path)
    
    # 创建文档
    doc = create_docx("D:\\vsc.py\\quanqiurenkou\\年报解读框架.docx")
    
    # 公司概况
    company_profile = "公司简介：[公司简介内容]\n主营业务：[主营业务内容]\n行业地位：[行业地位内容]"
    add_dimension(doc, "公司概况", company_profile)
    
    # 业绩速览
    performance_overview = "关键财务数据解读：[财务数据内容]"
    add_dimension(doc, "业绩速览", performance_overview)
    
    # 亮点与风险
    highlights_and_risks = "亮点信息：[亮点内容]\n风险提示：[风险内容]"
    add_dimension(doc, "亮点与风险", highlights_and_risks)
    
    # 行业瞭望
    industry_outlook = "行业发展趋势：[行业趋势内容]"
    add_dimension(doc, "行业瞭望", industry_outlook)
    
    # 未来展望
    future_outlook = "发展战略：[发展战略内容]\n未来规划：[未来规划内容]"
    add_dimension(doc, "未来展望", future_outlook)
    
    # 保存文档
    save_docx(doc, "D:\\vsc.py\\quanqiurenkou\\年报解读框架.docx")

if __name__ == "__main__":
    main()

import jieba
import jieba.posseg as pseg
from docx import Document

# 读取年报文本
def load_text(file_path):
    with open(file_path, "r", encoding="utf-8") as file:
        content = file.read()
        print("文本加载成功。")
        return content

# 创建 Word 文档
def create_docx(filename):
    doc = Document()
    doc.add_heading('年报解读框架', 0)
    print(f"文档 {filename} 创建成功。")
    return doc

# 添加解读维度到文档
def add_dimension(doc, dimension, content):
    doc.add_heading(dimension, level=1)
    doc.add_paragraph(content)
    print(f"维度 '{dimension}' 已添加。")

# 保存文档
def save_docx(doc, filename):
    doc.save(filename)
    print(f"文档已保存至 {filename}。")

# 主函数
def main():
    print("开始执行脚本...")
    file_path = "D:\\vsc.py\\quanqiurenkou\\key_info.txt"
    context = load_text(file_path)
    
    # 创建文档
    doc_filename = "D:\\vsc.py\\quanqiurenkou\\年报解读框架.docx"
    doc = create_docx(doc_filename)
    
    # 添加各个维度
    dimensions = {
        "公司概况": "公司简介：[公司简介内容]\n主营业务：[主营业务内容]\n行业地位：[行业地位内容]",
        "业绩速览": "关键财务数据解读：[财务数据内容]",
        "亮点与风险": "亮点信息：[亮点内容]\n风险提示：[风险内容]",
        "行业瞭望": "行业发展趋势：[行业趋势内容]",
        "未来展望": "发展战略：[发展战略内容]\n未来规划：[未来规划内容]"
    }
    for dimension, content in dimensions.items():
        add_dimension(doc, dimension, content)
    
    # 保存文档
    save_docx(doc, doc_filename)
    print("脚本执行完毕。")

if __name__ == "__main__":
    main()